package model;

import javax.persistence.Entity;
import javax.persistence.Id;

import dao.DaoJPA;

/**
 * 
 * @author Lars
 *
 */

@Entity
public class Statistik {
	@Id
	private int id = 1;
	
	private static Statistik instance;
	
	private int antalBehandlinger;
	private int antalForGamleBehandlinger;
	
	private Statistik() {
		this.antalBehandlinger = 0;
		this.antalForGamleBehandlinger = 0;
	}
	
	public static Statistik getInstance() {
		if(instance == null) {
			Statistik s = DaoJPA.getInstance().getStatistik();
			if(s != null) {
				instance = s;
			}
			else {
				instance = new Statistik();
			}
		}
		
		return instance;
	}
	
	public void setAntalBehandlinger(int antal) {
		this.antalBehandlinger = antal;
	}
	
	public void setAntalForGamleBehandlinger(int antal) {
		this.antalForGamleBehandlinger = antal;
	}
	
	public int getAntalBehandlinger() {
		return this.antalBehandlinger;
	}
	
	public int getAntalForGamleBehandlinger() {
		return this.antalForGamleBehandlinger;
	}
	
	public void countAntalBehandlinger() {
		this.antalBehandlinger++;
	}
	
	public void countForGamleBehandlinger() {
		this.antalForGamleBehandlinger++;
	}
	
	public double getForGamleProcent() {
		if(this.antalForGamleBehandlinger == 0) {
			return 0;
		}
		else {
			return (100*this.antalForGamleBehandlinger)/this.antalBehandlinger;
		}
	}
}
